package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Commodity;
import cn.wolfcode.trip.base.mapper.CommodityMapper;
import cn.wolfcode.trip.base.query.CommodityQueryObject;
import cn.wolfcode.trip.base.service.ICommodityService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommodityServiceImpl implements ICommodityService {

    @Autowired
    private CommodityMapper commodityMapper;

    @Override
    public void saveOrUpdate(Commodity commodity) {
        if (commodity.getId() != null) {
            commodityMapper.updateByPrimaryKey(commodity);
        } else {
            commodityMapper.insert(commodity);
        }
    }
    

    @Override
    public PageInfo query(CommodityQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Commodity> list = commodityMapper.selectForList(qo);
        return new PageInfo(list);
    }

}
